 /**
 * 逻辑、功能相关描述:
 *
 * @author 王浩羽 编写日期：Dec 30, 2008
 */
package com.ce.pms.occupation.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import com.ce.pms.base.service.impl.PmsBaseServiceImpl;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.customer.model.IdTypeDO;
import com.ce.pms.customer.model.ParticipantDO;
import com.ce.pms.customer.service.IClientRHouseService;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.model.CoalitionHouseDomain;
import com.ce.pms.house.model.HouseDomain;
import com.ce.pms.house.service.IHouseService;
import com.ce.pms.occupation.dao.IConsignAgentDao;
import com.ce.pms.occupation.dao.IIdentityValidateDao;
import com.ce.pms.occupation.model.ConsignAgentDO;
import com.ce.pms.occupation.model.IdentityValidateDO;
import com.ce.pms.occupation.model.OccHouseClientInfoDO;
import com.ce.pms.occupation.service.IIdentityValidateService;
import com.ce.pms.occupation.vo.IdentityValidateVO;
import com.ce.pms.occupation.vo.OccHouseClientInfoVO;
import com.ce.pms.occupation.vo.OccupationQueryConditionVO;
import com.ce.util.BeanUtil;
import com.sitechasia.webx.core.support.Page;
import com.sitechasia.webx.core.utils.base.PopulateUtil;

/**
 * 入伙身份验证Service
 * @author 王浩羽
 *
 */
public class IdentityValidateServiceImpl extends PmsBaseServiceImpl implements IIdentityValidateService
{
	private IIdentityValidateDao identityValidateDao;
	private IClientRHouseService clientRHouseService;
	private IHouseService houseService;
	private IConsignAgentDao consignAgentDao;
	public void setConsignAgentDao(IConsignAgentDao consignAgentDao)
	{
		this.consignAgentDao = consignAgentDao;
	}
	public void setHouseService(IHouseService houseService)
	{
		this.houseService = houseService;
	}

	public void setClientRHouseService(IClientRHouseService clientRHouseService)
	{
		this.clientRHouseService = clientRHouseService;
	}

	public void setIdentityValidateDao(IIdentityValidateDao identityValidateDao)
	{
		this.identityValidateDao = identityValidateDao;
	}

	public IdentityValidateVO addIdentityValidate(IdentityValidateVO identityValidateVO)
	{
		//入伙模式 001 以产权房办理入伙 002 以管理房办理入伙
		String joinMode = identityValidateVO.getJoinMode();
		Long houseId = identityValidateVO.getHouseId();
		if(!isAllowAddIdentityValidate(identityValidateVO))
		{
			throw new BusinessException("occupation:occupation_identityValidate_add_exception", BusinessException.WARNING);
		}
		
		IdentityValidateDO identityValidateDO = new IdentityValidateDO();

		HouseDomain house = new HouseDomain(houseId);
		identityValidateDO.setHouse(house);

		identityValidateDO.setJoinMode(joinMode);
		String coalitionHouseNumber = identityValidateVO.getCoalitionHouseNumber();
		Set<OccHouseClientInfoDO> houseClientInfoSet = identityValidateDO.getClientInfos();
		Set<OccHouseClientInfoDO> occHouseClientInfoDOset = assembleOccHouseClientInfoSetV2D(identityValidateVO.getClientInfos(), houseClientInfoSet, identityValidateDO, coalitionHouseNumber);
		identityValidateDO.setClientInfos(occHouseClientInfoDOset);
		String transactJoinIdentity = identityValidateVO.getTransactJoinIdentity();
		identityValidateDO.setTransactJoinIdentity(transactJoinIdentity);
		//如果是委托代理
		if(transactJoinIdentity.equals(SysrefcodeDO.JOIN_IDENTITY_MODE_AGENT))
		{
			ConsignAgentDO agentDO = extractConsignAgent(identityValidateVO, null);
			identityValidateDO.setConsignAgent(agentDO);
			agentDO.setSysInfo(createInfo(identityValidateVO.getCreator()));
		}
		identityValidateDO.setClientName(identityValidateVO.getClientName());
		identityValidateDO.setDescription(identityValidateVO.getDescription());
		identityValidateDO.setIdentityState(SysrefcodeDO.CONSTANTS_DIGITAL_ONE);
		fixValues(identityValidateDO);
		identityValidateDao.saveObject(identityValidateDO);
		//保留，以后扩展再用 notifyIdentityValidateOk(Long identityValidateId)
		return identityValidateVO;

	}

	/**
	 * 功能描述: 修正默认值 <br>
	 * @param identityValidateDO
	 * Create author: 王浩羽 <br>
	 * Create on:Jan 23, 2009  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private void fixValues(IdentityValidateDO identityValidateDO){
//		if(!StringUtils.hasText(identityValidateDO.getIdentityState()))
//		{
//			identityValidateDO.setIdentityState(SysrefcodeDO.CONSTANTS_DIGITAL_ZERO);
//		}
		if(!StringUtils.hasText(identityValidateDO.getDocState()))
		{
			identityValidateDO.setDocState(SysrefcodeDO.CONSTANTS_DIGITAL_ZERO);
		}
		if(!StringUtils.hasText(identityValidateDO.getChargeState()))
		{
			identityValidateDO.setChargeState(SysrefcodeDO.CONSTANTS_DIGITAL_ZERO);
		}
		if(!StringUtils.hasText(identityValidateDO.getHandoverState()))
		{
			identityValidateDO.setHandoverState(SysrefcodeDO.CONSTANTS_DIGITAL_ZERO);
		}
		if(!StringUtils.hasText(identityValidateDO.getInspectCheckinState()))
		{
			identityValidateDO.setInspectCheckinState(SysrefcodeDO.CONSTANTS_DIGITAL_ZERO);
		}
	}
	/**
	 * 功能描述: 从IdentityValidateVO中抽取数据生成ConsignAgentDO <br>
	 * @param identityValidateVO
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Dec 31, 2008  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private ConsignAgentDO extractConsignAgent(IdentityValidateVO identityValidateVO,ConsignAgentDO consignAgentDO){
		ConsignAgentDO agentDO = consignAgentDO;
		if(agentDO==null)
		{
			agentDO = new ConsignAgentDO();
		}
		agentDO.setKeyword(identityValidateVO.getConsignAgentId());
		agentDO.setConsignAgentName(identityValidateVO.getConsignAgentName());
		IdTypeDO idTypeDO = new IdTypeDO(identityValidateVO.getConsignAgentIdTypeId());
		agentDO.setIdType(idTypeDO);
		agentDO.setIdNumber(identityValidateVO.getConsignAgentIdNumber());
		agentDO.setLinkmanPhone(identityValidateVO.getConsignAgentLinkmanPhone());
		return agentDO;
	}

	/**
	 * 功能描述: 把Set中的对象从VO转成DO <br>
	 * @param voSet
	 * @param doSet
	 * @param identityValidateDO
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Dec 31, 2008  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private Set<OccHouseClientInfoDO> assembleOccHouseClientInfoSetV2D(Set<OccHouseClientInfoVO> voSet, Set<OccHouseClientInfoDO> doSet, IdentityValidateDO identityValidateDO,String coalitionHouseNumber){
		Assert.notNull(voSet);
		Assert.notNull(doSet);
		for(OccHouseClientInfoVO infoVO : voSet)
		{
			OccHouseClientInfoDO infoDO = assembleOccHouseClientInfoV2D(infoVO,null);
			infoDO.setIdentityValidateDO(identityValidateDO);
			infoDO.setCoalitionHouseNumber(coalitionHouseNumber);
			doSet.add(infoDO);
		}
		return doSet;
	}

	/**
	 * 功能描述: OccHouseClientInfo的VO转成DO <br>
	 * @param infoVO
	 * @param infoDO
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Dec 31, 2008  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private OccHouseClientInfoDO assembleOccHouseClientInfoV2D(OccHouseClientInfoVO infoVO, OccHouseClientInfoDO infoDO){
		OccHouseClientInfoDO targetDO = infoDO;
		if(targetDO==null)
		{
			targetDO = new OccHouseClientInfoDO();
		}
		BeanUtil.convertVoAsDo(infoVO, targetDO);
		return targetDO;
	}

	/**
	 * 功能描述: OccHouseClientInfo的DO转成VO <br>
	 * @param infoDO
	 * @param infoVO
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Dec 31, 2008  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private OccHouseClientInfoVO assembleOccHouseClientInfoD2V(OccHouseClientInfoDO infoDO, OccHouseClientInfoVO infoVO){
		OccHouseClientInfoVO targetVO = infoVO;
		if(targetVO==null)
		{
			targetVO = new OccHouseClientInfoVO();
		}
		PopulateUtil.populate(infoDO, targetVO);
		return targetVO;
	}

	/**
	 * 功能描述: 把Set中的对象从DO转成VO  <br>
	 * @param doSet
	 * @param voSet
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Jan 4, 2009  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private Set<OccHouseClientInfoVO> assembleOccHouseClientInfoSetD2V(Set<OccHouseClientInfoDO> doSet, Set<OccHouseClientInfoVO> voSet){
		Assert.notNull(voSet);
		Assert.notNull(doSet);
		for(OccHouseClientInfoDO infoDO : doSet)
		{
			OccHouseClientInfoVO infoVO = assembleOccHouseClientInfoD2V(infoDO,null);
			voSet.add(infoVO);
		}
		return voSet;
	}
	/**
	 * 功能描述: 是否允许新增认证 <br>
	 * 1、入伙房号必须存在对应的业主信息。<br>
	 * 2、管理房对应的各个产权房的入伙方式要一致。<br>
	 * 3、如果房号已经处于入伙状态或入伙成功，不能进行入伙。<br>
	 * @param houseId
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Dec 31, 2008  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private boolean isAllowAddIdentityValidate(IdentityValidateVO identityValidateVO){
		Long houseId = identityValidateVO.getHouseId();
		//已经入伙，不能重复入伙
		IdentityValidateDO identityValidateDO = identityValidateDao.findUniqueByHouseId(houseId);
		if(identityValidateDO!=null)
		{
			return false;
		}
		List<ParticipantDO> owners = clientRHouseService.getAllOwnerByHouseId(houseId);
		if(owners == null || owners.isEmpty())
		{
			return false;
		}
		//获取有效的管理房
		CoalitionHouseDomain coalitionHouseDomain = houseService.getCoalition(houseId);
		if(coalitionHouseDomain==null)
		{
			return true;
		}
		Set<HouseDomain> houses = coalitionHouseDomain.getHouses();

		if(isContainsHouse(houses,identityValidateVO.getHouseNumber()))//同一个管理房下的房子
		{
			for(HouseDomain houseDomain : houses)
			{
				IdentityValidateDO identityDO = identityValidateDao.findUniqueByHouseId(houseDomain.getKeyword());
				if(identityDO!=null)
				{
					//如果已经有房子以管理房入伙，则不能再入伙
					if(SysrefcodeDO.OCCUPATION_IN_MANAGEHOUSE.equals(identityDO.getJoinMode()))
					{
						return false;
					}
				}
			}
			return true;
		}
		return true;
	}

	/**
	 * 功能描述:房屋列表中是否包含有给定房间号码的房间 <br>
	 * @param houses
	 * @param houseNumber
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Jan 12, 2009  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private boolean isContainsHouse(Set<HouseDomain> houses, String houseNumber){
		if(houses==null || houses.isEmpty())
		{
			return false;
		}
		for(HouseDomain houseDomain : houses)
		{
			if(houseDomain.getHouseNumber().equals(houseNumber))
			{
				return true;
			}
		}
		return false;
	}


	public void delIdentityValidate(Long identityValidateId)
	{
		if(isAllowDelIdentityValidate(identityValidateId))
		{
			identityValidateDao.deleteObjectById(identityValidateId);
		}
	}

	/**
	 * 功能描述: 是否允许删除认证  <br>
	 * 如果有资料发放、验房、预缴款、钥匙移交任何一个操作，都不能进行删除操作
	 * @param id
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Dec 31, 2008  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public boolean isAllowDelIdentityValidate(Long id){
		IdentityValidateDO identityValidateDO = identityValidateDao.findById(id);
		if(identityValidateDO.getDocState().equals(SysrefcodeDO.CONSTANTS_DIGITAL_ONE))//资料已发放
		{
			return false;
		}
		if(identityValidateDO.getInspectCheckinState().equals(SysrefcodeDO.CONSTANTS_DIGITAL_ONE))//已验房登记
		{
			return false;
		}
		if(identityValidateDO.getChargeState().equals(SysrefcodeDO.CONSTANTS_DIGITAL_ONE))//已缴款
		{
			return false;
		}
		if(identityValidateDO.getHandoverState().equals(SysrefcodeDO.CONSTANTS_DIGITAL_ONE))//钥匙已移交
		{
			return false;
		}
		return true;
	}

	/**
	 * 功能描述: 是否允许修改认证登记 <br>
	 * 1、入伙房号不得更改。<br>
	 * 2、如果有资料发放、验房、预缴款、钥匙移交任何一个操作，都不能进行修改操作。<br>
	 * 3、如果按管理房号办理，如果已经有隶属管理房的产权房已经办理了入伙，则不允许继续按管理房号办理入伙验证（即：管理房对应的各个产权房的入伙方式要一致）。<br>
	 * @param id
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Jan 12, 2009  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private boolean isAllowEditIdentityValidate(Long id){
		if(!isAllowDelIdentityValidate(id))//修改条件包含删除条件，即不满足删除条件的也不会满足修改条件
		{
			return false;
		}
		//目前所选的入伙验证都是按产权房进行
		return true;
	}
	public IdentityValidateVO editIdentityValidate(IdentityValidateVO identityValidateVO)
	{
		if(!isAllowEditIdentityValidate(identityValidateVO.getKeyword()))
		{
			throw new BusinessException("occupation:occupation_identityValidate_edit_exception", BusinessException.WARNING);
		}


		IdentityValidateDO identityValidateDO = identityValidateDao.findById(identityValidateVO.getKeyword());
		String transactJoinIdentity = identityValidateVO.getTransactJoinIdentity();
		identityValidateDO.setTransactJoinIdentity(transactJoinIdentity);
		//如果是委托代理
		if(transactJoinIdentity.equals(SysrefcodeDO.JOIN_IDENTITY_MODE_AGENT))
		{
			ConsignAgentDO agentDO = identityValidateDO.getConsignAgent();
			agentDO = extractConsignAgent(identityValidateVO, agentDO);
			if(agentDO.getKeyword()==null)
			{
				agentDO.setSysInfo(createInfo(identityValidateVO.getModifier()));
			}else{
				modifyInfo(agentDO.getSysInfo(), identityValidateVO.getModifier());
			}
			identityValidateDO.setConsignAgent(agentDO);
		}else{
			ConsignAgentDO oldAgentDO = identityValidateDO.getConsignAgent();
			identityValidateDO.setConsignAgent(null);
			if(oldAgentDO!=null)
			{
				consignAgentDao.deleteObject(oldAgentDO);
			}
		}
		identityValidateDO.setClientName(identityValidateVO.getClientName());
		identityValidateDO.setDescription(identityValidateVO.getDescription());


		identityValidateDao.updateObject(identityValidateDO);
		return identityValidateVO;
	}

	public IdentityValidateVO getIdentityValidateDetail(Long identityValidateId)
	{
		IdentityValidateDO identityValidateDO = identityValidateDao.findById(identityValidateId);
		IdentityValidateVO identityValidateVO = new IdentityValidateVO();
		if(identityValidateDO==null)
		{
			return null;
		}
		assembleIdentityValidateD2V(identityValidateDO, identityValidateVO);
		return identityValidateVO;
	}
	public void notifyIdentityValidateOk(Long identityValidateId){
		IdentityValidateDO identityValidateDO = identityValidateDao.findById(identityValidateId);
		identityValidateDO.setIdentityState(SysrefcodeDO.CONSTANTS_DIGITAL_ONE);
		identityValidateDao.saveOrUpdateObject(identityValidateDO);
	}
	public void receiveAddedDocumentReceiveSend(Long identityValidateId)
	{
		IdentityValidateDO identityValidateDO = identityValidateDao.findById(identityValidateId);
		identityValidateDO.setDocState(SysrefcodeDO.CONSTANTS_DIGITAL_ONE);// 设置文档收发状态 1 ： 已收发
		identityValidateDao.saveOrUpdateObject(identityValidateDO);

	}

	public void receiveAddedOccInspectionRequisition(Long identityValidateId,String result)
	{
		IdentityValidateDO identityValidateDO = identityValidateDao.findById(identityValidateId);
		// 001 ：未验房;(身份验证通过，但还没验房) 002 ：整改中;(已验过房，但没通过，处于整改中) 003 ：验房通过;
		identityValidateDO.setInspectResult(result);
		identityValidateDO.setInspectCheckinState(SysrefcodeDO.CONSTANTS_DIGITAL_ONE);//有验房，不一定是通过的
		identityValidateDao.saveOrUpdateObject(identityValidateDO);
	}
	/**
	   * 功能描述:通知身份验证，已预缴款  <br>
	   * @param identityValidateId - 身份验证ID
	   * @roseuid 4954452D0177
	   * Create author:王浩羽 <br>
	   * Create on:2009-1-13  <br>
	   * Edit author:  <br>
	   * Edit on:    <br>
	   * Why:     <br>
	   */
	public void receiveAddedOccupationCharge(Long identityValidateId) {
		IdentityValidateDO identityValidateDO = identityValidateDao.findById(identityValidateId);
		identityValidateDO.setChargeState(SysrefcodeDO.CONSTANTS_DIGITAL_ONE);//设成费用已缴
		identityValidateDao.updateObject(identityValidateDO);
	}

	public void receiveAddedThingHandover(Long identityValidateId, String status)
	{
		IdentityValidateDO identityValidateDO = identityValidateDao.findById(identityValidateId);
		identityValidateDO.setHandoverState(status);//
		identityValidateDao.saveOrUpdateObject(identityValidateDO);
	}

	public Page queryIdentityValidateList(OccupationQueryConditionVO queryCondition)
	{
		queryCondition.checkRule();
		Page result = identityValidateDao.queryIdentityValidateList(queryCondition);
		List<IdentityValidateDO> identityValidateDOList = result.getResult();
		if(identityValidateDOList==null || identityValidateDOList.isEmpty())
		{
			result.setResult(Collections.EMPTY_LIST);
			return result;
		}
		result.setResult(assembleIdentityValidateDOList2OccupationQueryConditionVOList(identityValidateDOList));
		return result;
	}

	/**
	 * 功能描述: IdentityValidateDO列表 转换成 OccupationQueryConditionVO 列表<br>
	 * @param identityValidateDOList
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Dec 31, 2008  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private List<OccupationQueryConditionVO> assembleIdentityValidateDOList2OccupationQueryConditionVOList(List<IdentityValidateDO> identityValidateDOList){
		List<OccupationQueryConditionVO> occupationQueryConditionVOList = new ArrayList<OccupationQueryConditionVO>();
		for(IdentityValidateDO identityValidateDO : identityValidateDOList)
		{
			OccupationQueryConditionVO occupationQueryConditionVO = assembleIdentityValidateDO2OccupationQueryConditionVO(identityValidateDO);
			occupationQueryConditionVOList.add(occupationQueryConditionVO);
		}
		return occupationQueryConditionVOList;
	}

	/**
	 * 功能描述: IdentityValidateDO 转换成 OccupationQueryConditionVO <br>
	 * @param identityValidateDO
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Dec 31, 2008  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private OccupationQueryConditionVO assembleIdentityValidateDO2OccupationQueryConditionVO(IdentityValidateDO identityValidateDO){
		OccupationQueryConditionVO queryCondition = new OccupationQueryConditionVO();
		queryCondition.setIdentityValidateId(identityValidateDO.getKeyword());
		queryCondition.setBuildingDomainId(identityValidateDO.getHouse().getBuilding().getKeyword());
		queryCondition.setBuildingDomainName(identityValidateDO.getHouse().getBuilding().getName());
		if(identityValidateDO.getJoinMode().equals(SysrefcodeDO.OCCUPATION_IN_MANAGEHOUSE))
		{   //管理房入伙时，显示多个房号
			queryCondition.setHouseNumber(getAllHouseNumber(identityValidateDO.getClientInfos()));
		}
		else{
			queryCondition.setHouseNumber(identityValidateDO.getHouse().getHouseNumber());
		}
		queryCondition.setIdentityState(identityValidateDO.getIdentityState());
		queryCondition.setDocState(identityValidateDO.getDocState());
		queryCondition.setChargeState(identityValidateDO.getChargeState());
		queryCondition.setInspectCheckinState(identityValidateDO.getInspectCheckinState());
		queryCondition.setHandoverState(identityValidateDO.getHandoverState());
		queryCondition.setInspectResult(identityValidateDO.getInspectResult());
		queryCondition.setOwnerName(identityValidateDO.getClientName());
		queryCondition.setCoalitionHouseNumber(searchCoalitionHouseNumber(identityValidateDO.getClientInfos()));
		return queryCondition;
	}
	/**
	 * 功能描述:拼装所有产权房房号，逗号为分隔符  <br>
	 * @param clientInfos
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Jan 15, 2009  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String getAllHouseNumber(Set<OccHouseClientInfoDO> clientInfos){
		StringBuilder houseStringBuilder = new StringBuilder();
		for(OccHouseClientInfoDO occHouseClientInfoDO : clientInfos)
		{
			houseStringBuilder.append(occHouseClientInfoDO.getRealHouseNumber()).append(",");
		}
		if(!clientInfos.isEmpty() && houseStringBuilder.lastIndexOf(",")==houseStringBuilder.length()-1)
		{
			houseStringBuilder.deleteCharAt(houseStringBuilder.lastIndexOf(","));
		}
		return houseStringBuilder.toString();
	}

//	/**
//	 * 功能描述:拼装所有产权房房主，逗号为分隔符  <br>
//	 * @param clientInfos
//	 * @return
//	 * Create author: 王浩羽 <br>
//	 * Create on:Jan 15, 2009  <br>
//	 * Edit author:  <br>
//	 * Edit on:    <br>
//	 * Why:     <br>
//	 */
//	public String getAllOwnerNames(Long houseId){
//		List<ParticipantDO> owners = clientRHouseService.getAllOwnerByHouseId(houseId);
//		StringBuilder ownerStringBuilder = new StringBuilder();
//		for(ParticipantDO participantDO : owners)
//		{
//			ownerStringBuilder.append(participantDO.getParticipantName()).append(",");
//		}
//		if(!owners.isEmpty() && ownerStringBuilder.lastIndexOf(",")==ownerStringBuilder.length()-1)
//		{
//			ownerStringBuilder.deleteCharAt(ownerStringBuilder.lastIndexOf(","));
//		}
//		return ownerStringBuilder.toString();
//	}

	/**
	 * 功能描述: 寻找关联管理房的房号 <br>
	 * @param clientInfos
	 * @return
	 * Create author: 王浩羽 <br>
	 * Create on:Jan 4, 2009  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private String searchCoalitionHouseNumber(Set<OccHouseClientInfoDO> clientInfos){
		Assert.notNull(clientInfos);
		for(OccHouseClientInfoDO occHouseClientInfoDO : clientInfos)
		{
			if(StringUtils.hasText(occHouseClientInfoDO.getCoalitionHouseNumber()))
			{
				return occHouseClientInfoDO.getCoalitionHouseNumber();
			}
		}
		return null;
	}


	public void assembleIdentityValidateD2V(IdentityValidateDO identityValidateDO, IdentityValidateVO identityValidateVO){
		PopulateUtil.populate(identityValidateDO, identityValidateVO, new String[]{"clientInfos"});
		if(identityValidateDO.getClientInfos()!=null)
		{
			Set<OccHouseClientInfoVO> clientInfos = assembleOccHouseClientInfoSetD2V(identityValidateDO.getClientInfos(), identityValidateVO.getClientInfos());
			identityValidateVO.setClientInfos(clientInfos);
		}
		ConsignAgentDO consignAgent = identityValidateDO.getConsignAgent();
		HouseDomain house = identityValidateDO.getHouse();
		if(consignAgent!=null)
		{
			identityValidateVO.setConsignAgentId(consignAgent.getKeyword());
			identityValidateVO.setConsignAgentIdNumber(consignAgent.getIdNumber());
			if(consignAgent.getIdType()!=null)
			{
				identityValidateVO.setConsignAgentIdTypeId(consignAgent.getIdType().getIdTypeId());
			}
			identityValidateVO.setConsignAgentLinkmanPhone(consignAgent.getLinkmanPhone());
			identityValidateVO.setConsignAgentName(consignAgent.getConsignAgentName());
		}
		if(house!=null)
		{
			identityValidateVO.setHouseId(house.getKeyword());
			identityValidateVO.setHouseNumber(house.getHouseNumber());
		}
	}

	public void assembleIdentityValidateV2D(IdentityValidateVO identityValidateVO, IdentityValidateDO identityValidateDO)
	{
		PopulateUtil.populate(identityValidateVO, identityValidateDO, new String[]{"clientInfos"});
		String coalitionHouseNumber = identityValidateVO.getCoalitionHouseNumber();
		Set<OccHouseClientInfoDO> clientInfos = assembleOccHouseClientInfoSetV2D(identityValidateVO.getClientInfos(), identityValidateDO.getClientInfos(),identityValidateDO, coalitionHouseNumber);
		identityValidateDO.setClientInfos(clientInfos);


		ConsignAgentDO consignAgent = new ConsignAgentDO(identityValidateVO.getConsignAgentId());;
		consignAgent.setIdNumber(identityValidateVO.getConsignAgentIdNumber());
		consignAgent.setIdType(new IdTypeDO(identityValidateVO.getConsignAgentIdTypeId()));
		consignAgent.setLinkmanPhone(identityValidateVO.getConsignAgentLinkmanPhone());
		consignAgent.setConsignAgentName(identityValidateVO.getConsignAgentName());
		identityValidateDO.setConsignAgent(consignAgent);

		HouseDomain house = new HouseDomain(identityValidateVO.getHouseId());
		house.setHouseNumber(identityValidateVO.getHouseNumber());
		identityValidateDO.setHouse(house);
	}

	public IdentityValidateVO findIdentityValidateVOByHouseId(Long houseId){
		IdentityValidateDO identityValidateDO = identityValidateDao.findUniqueByHouseId(houseId);
		if(identityValidateDO==null)//主房间查询不到
		{
			//那么从关联房间查询
			CoalitionHouseDomain coalitionHouseDomain = houseService.getCoalition(houseId);
			if(coalitionHouseDomain==null)
			{
				return null;//没有管理房，那么只能返回空了
			}
			Set<HouseDomain> houses = coalitionHouseDomain.getHouses();//存在其他管理房间
			for(HouseDomain houseDomain : houses)
			{
				if(houseDomain.getKeyword().longValue()!=houseId)//不要再查主房间的认证了
				{
					identityValidateDO = identityValidateDao.findUniqueByHouseId(houseDomain.getKeyword());
					if(identityValidateDO!=null && SysrefcodeDO.CONSTANTS_DIGITAL_ONE.equals(identityValidateDO.getIdentityState()))
					{
						break;//如果找到了，就跳出
					}
				}
			}
		}
		if(identityValidateDO==null)//如果还是没有找到，那么就返回null
		{
			return null;
		}
		IdentityValidateVO identityValidateVO = new IdentityValidateVO();
		assembleIdentityValidateD2V(identityValidateDO, identityValidateVO);
		return identityValidateVO;
	}
}
